﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using KSOAdmin.Core.AppsettingHelper;

using MongoDB.Driver;

namespace KSOAdmin.Core.MongoDbHelper
{
    public class MongoDbContext
    {
        public static class MongodbClient<T> where T : class
        {
            #region +MongodbInfoClient 获取mongodb实例
            /// <summary>
            /// 获取mongodb实例
            /// </summary>
            /// <param name="host">连接字符串，库，表</param>
            /// <returns></returns>
            public static IMongoCollection<T> MongodbInfoClient(string Table)
            {
                MongodbHost host=Appsettings.GetConfigClass<MongodbHost>("MongoDBString");
                MongoClient client = new MongoClient(host.Connection);
                var dataBase = client.GetDatabase(host.DbName);
                return dataBase.GetCollection<T>( Table);
            }
            #endregion
        }

        public class MongodbHost
        {
            /// <summary>
            /// 连接字符串
            /// </summary>
            public string Connection { get; set; }
            /// <summary>
            /// 库
            /// </summary>
            public string DbName { get; set; }
             

        }
    }
}
